package com.csx.base.concurrency;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <p> what does this class do ? </p>
 * <p> How does it work ?</p>
 * <p> Why does it do this ?</p>
 *
 * @author cuisongxu
 * @date 2024/11/24 周日 16:34
 */
public class TestReentrantLockLock implements Runnable{
    static ReentrantLock lock = new ReentrantLock();
    @Override
    public void run() {
        lock.lock();
        try {
            TimeUnit.SECONDS.sleep(99999);

        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        TestReentrantLockLock task = new TestReentrantLockLock();
        Thread thread = new Thread(task);
        thread.start();
        TimeUnit.SECONDS.sleep(5);
        lock.lock();
        try {
            TimeUnit.SECONDS.sleep(15);

        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }

    }
}
